package com.jcl.mybatistypehandler.web;

import com.jcl.mybatistypehandler.dao.UserDao;
import com.jcl.mybatistypehandler.model.MyEncrypt;
import com.jcl.mybatistypehandler.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    private UserDao userDao;

    @GetMapping("add")
    public String addUser(@RequestParam("name") String name,
                          @RequestParam("phone") String phone,
                          @RequestParam("remark") String remark) {
        MyEncrypt myEncrypt = new MyEncrypt(phone);
        int result = userDao.add(name, myEncrypt, remark);
        return "添加结果: " + result;
    }

    @GetMapping("findByPhone")
    public User findCustomer(@RequestParam("phone") String phone) {
        return userDao.findByPhone(new MyEncrypt(phone));
    }
}
